#! /usr/bin/env python
# -*- coding: utf-8 -*-
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer
from thrift.transport import TSocket
from thrift.transport import TTransport

from conf import setting
from utils.redis_obj import RedisObj
from .server import RedisServer


def run():
    handler = RedisServer()

    processor = RedisObj.Processor(handler)
    transport = TSocket.TServerSocket(setting.__HOST, setting.__PORT)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()

    rpcServer = TServer.TSimpleServer(processor, transport, tfactory, pfactory)

    print('Starting the redis rpc server at', setting.__HOST, ':', setting.__PORT)
    rpcServer.serve()
